import type { TableColumn } from '@/framework/components/core/super-table';
import dayjs from 'dayjs';
import AsyncSelect from '@/components/search-header/async-select.vue';
import { i18n } from '@/locales';
import { getWordAssociative } from '@/api/common/common_data';
import { shallowRef } from 'vue';

export type TableListItem = {
  name;
  type;
  serial;
  epc;
  originalSerial;
  inTime;
  outTime;
};
export type TableColumnItem = TableColumn<TableListItem>;

export const baseColumns: TableColumnItem[] = [
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    // @ts-ignore
    title: i18n.global.t('specimen.name'),
    field: 'name',
    formItemProps: {
      component: shallowRef(AsyncSelect),
      componentProps: {
        fetchData: async (params) => {
          const res = await getWordAssociative('specimen_name', params, 5);
          return res.result.map((item) => ({
            label: item,
            value: item,
          }));
        },
      },
    },
  },
  {
    title: '存储类型',
    field: 'type',
    hideInSearch: true,
    formatter: ({ cellValue }) => {
      return cellValue === 3 ? '暂存样本' : '保藏样本';
    },
  },
  {
    title: '序列号',
    field: 'serial',
    hideInSearch: true,
  },
  {
    // @ts-ignore
    title: i18n.global.t('specimen.epc'),
    field: 'epc',
    hideInSearch: true,
  },
  {
    // @ts-ignore
    title: i18n.global.t('specimen.original_serial'),
    field: 'originalSerial',
  },

  {
    title: '入库时间',
    field: 'inTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
    searchField: 'inTimeBtw',
    formItemProps: {
      component: 'RangePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
      },
    },
  },
  {
    title: '出库时间',
    field: 'outTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
    searchField: 'outTimeBtw',
    formItemProps: {
      component: 'RangePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
      },
    },
  },
];
